<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>角色添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.15&key=76e7d4bddd0c61640b4ed94a44b5ac1e&plugin=AMap.CitySearch"></script>
    <style type="text/css">
        .readOnly{
            color: rgba(90, 39, 40, 0.4);
        }
    </style>
</head>
<body>

<div class="layui-form" lay-filter="layuiadmin-form-role" id="layuiadmin-form-role" style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">城市名</label>
        <div class="layui-input-block">
            <input type="text" name="cty_name"  class="layui-input" lay-verify="required" placeholder="请输入城市名称">
        </div>
    </div>
    <!--这个div用来放置地图-->
    <div class="layui-form-item">
        <label class="layui-form-label">选取地址</label>
        <div class="layui-input-block" id="container" style="height: 300px;">

        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">地理经度</label>
        <div class="layui-input-block">
            <input type="text"  name="cty_longitude" id="cty_longitude" readonly autocomplete="off" class="layui-input readOnly">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">地理纬度</label>
        <div class="layui-input-block">
            <input type="text"  name="cty_latitude" id="cty_latitude"  readonly autocomplete="off" class="layui-input readOnly">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">缩放层级</label>
        <div class="layui-input-block">
            <input type="text"  name="cty_zoom" id="cty_zoom" readonly autocomplete="off" class="layui-input readOnly">
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <button class="layui-btn" lay-submit lay-filter="add" id="add">提交</button>
    </div>

</div>

<script src="/static/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form'], function(){
        var $ = layui.$
            ,form = layui.form ;

        var marker=new AMap.Marker({});
        var map = new AMap.Map('container', {
            zoom:11,//级别
            viewMode:'3D'//使用3D视图
        });
        map.on('click', function(e) {
            //获得点击参数，显示到页面上
            var longitude=e.lnglat.getLng();
            var latitude=e.lnglat.getLat();
            var zoom=map.getZoom();
            $("#cty_longitude").val(longitude);
            $("#cty_latitude").val(latitude);
            $("#cty_zoom").val(zoom);
            map.remove(marker);
            marker = new AMap.Marker({
                //获取点击点的经纬度
                position: [e.lnglat.getLng(), e.lnglat.getLat()]
            });
            map.add(marker);//添加到地图
        });
    })
</script>
</body>
</html>
